﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Security.Principal;
using System.Windows.Forms;

namespace milaninstaller
{
	static class Program
	{
		/// <summary>
		/// The entry point for the application.
		/// </summary>
		[STAThread]
		static void Main()
		{
			var configuration = ((AssemblyConfigurationAttribute)Attribute.GetCustomAttribute(Assembly.GetEntryAssembly(), typeof(AssemblyConfigurationAttribute), false)).Configuration;
			if(configuration[0]!='1')
				MakeSureRunningAsAdmin();
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
			Application.Run(new FormStart());
		}
		static void MakeSureRunningAsAdmin()
		{
			if (IsAdministrator() == false)
			{
				ProcessStartInfo startInfo = new ProcessStartInfo(Assembly.GetEntryAssembly().Location);
				startInfo.Verb = "runas";
				Process.Start(startInfo);
				Application.Exit();
			}
		}

		private static bool IsAdministrator()
		{
			WindowsIdentity identity = WindowsIdentity.GetCurrent();
			WindowsPrincipal principal = new WindowsPrincipal(identity);
			return principal.IsInRole(WindowsBuiltInRole.Administrator);
		}
	}
}
